package kr.ac.mju.mdc.mjuapp.green;

import kr.ac.mju.mdc.mjuapp.R;
import kr.ac.mju.mdc.mjuapp.network.NetworkManager;
import kr.ac.mju.mdc.mjuapp.util.PixelConverter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

/**
 * @author davidkim
 * 
 */
public class GreencampusMainActivity extends Activity implements OnClickListener {

	/* 인텐트로 넘겨줄 상수값 정의 */
	private final int WRITE_ARTS = 30; // 에너지낭비 신고하기(인문)
	private final int WRITE_SCIENCES = 31; // 에너지낭비 신고하기(자연)
	private final int WRITE_SELF = 32; // 본인조치 결과 신고하
	private final int WRITE_SUGGEST = 33; // 제안합니다

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.greencampus_main_layout);
		// TODO Auto-generated method stub

		((Button) findViewById(R.id.btn_green_write_arts)).setOnClickListener(this);
		((Button) findViewById(R.id.btn_green_write_sciences)).setOnClickListener(this);
		((Button) findViewById(R.id.btn_green_write_self)).setOnClickListener(this);
		((Button) findViewById(R.id.btn_green_write_suggest)).setOnClickListener(this);
		((ImageButton) findViewById(R.id.green_list_btn)).setOnClickListener(this);
		initLayout();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (NetworkManager.checkNetwork(GreencampusMainActivity.this)) {
			Intent intent = null;
			switch (v.getId()) {
			case R.id.btn_green_write_arts:
				intent = new Intent(GreencampusMainActivity.this, GreencampusWriteActivity.class);
				intent.putExtra("write_which", WRITE_ARTS);
				break;
			case R.id.btn_green_write_sciences:
				intent = new Intent(GreencampusMainActivity.this, GreencampusWriteActivity.class);
				intent.putExtra("write_which", WRITE_SCIENCES);
				break;
			case R.id.btn_green_write_self:
				intent = new Intent(GreencampusMainActivity.this, GreencampusWriteActivity.class);
				intent.putExtra("write_which", WRITE_SELF);
				break;
			case R.id.btn_green_write_suggest:
				intent = new Intent(GreencampusMainActivity.this, GreencampusWriteActivity.class);
				intent.putExtra("write_which", WRITE_SUGGEST);
				break;
			case R.id.green_list_btn:
				intent = new Intent(GreencampusMainActivity.this, GreencampusListActivity.class);
			default:
				break;
			}

			if (intent != null) {
				startActivity(intent);
			}
		}
	}

	/**
	 * 
	 */
	private void initLayout() {
		PixelConverter pixelConveter = new PixelConverter(this);
		LinearLayout.LayoutParams lParams = null;
		//green header layout
		lParams = (LayoutParams) findViewById(R.id.green_write_header_layout).getLayoutParams();
		lParams.height = pixelConveter.getHeight(62);
		// green top layout
		lParams = (LayoutParams) findViewById(R.id.green_write_top_layout).getLayoutParams();
		lParams.topMargin = pixelConveter.getHeight(33);
		lParams.bottomMargin = pixelConveter.getHeight(10);
		findViewById(R.id.green_write_top_layout).setLayoutParams(lParams);
		// btn green write arts
		lParams = (LayoutParams) findViewById(R.id.btn_green_write_arts).getLayoutParams();
		lParams.width = pixelConveter.getWidth(198);
		lParams.height = pixelConveter.getHeight(318);
		lParams.rightMargin = pixelConveter.getWidth(10);
		findViewById(R.id.btn_green_write_arts).setLayoutParams(lParams);
		// btn green sciences
		lParams = (LayoutParams) findViewById(R.id.btn_green_write_sciences).getLayoutParams();
		lParams.width = pixelConveter.getWidth(198);
		lParams.height = pixelConveter.getHeight(318);
		findViewById(R.id.btn_green_write_sciences).setLayoutParams(lParams);

		// btn green self
		lParams = (LayoutParams) findViewById(R.id.btn_green_write_self).getLayoutParams();
		lParams.width = pixelConveter.getWidth(198);
		lParams.height = pixelConveter.getHeight(318);
		lParams.rightMargin = pixelConveter.getWidth(10);
		findViewById(R.id.btn_green_write_self).setLayoutParams(lParams);
		// btn green suggest
		lParams = (LayoutParams) findViewById(R.id.btn_green_write_suggest).getLayoutParams();
		lParams.width = pixelConveter.getWidth(198);
		lParams.height = pixelConveter.getHeight(318);
		findViewById(R.id.btn_green_write_suggest).setLayoutParams(lParams);
	}
}
/* end of file */
